package com.zzt.zt_hilt

import android.content.Context
import dagger.hilt.android.AndroidEntryPoint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.zzt.zt_hilt.Module.MyWeather
import com.zzt.zt_hilt.databinding.ActivityMainBinding
import com.zzt.zt_hilt.entity.Car
import com.zzt.zt_hilt.entity.CodeV2
import com.zzt.zt_hilt.entity.Company
import com.zzt.zt_hilt.entity.CompanyModule1
import com.zzt.zt_hilt.inter.Work
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import com.zzt.zt_hilt.entity.tools

import com.zzt.zt_hilt.entity.Student
import com.zzt.zt_hilt.service.WheatherApi
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response


@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
    val TAG = "Hilt MainActivity"

    @Inject
    lateinit var car: Car;


    @Inject
    @CompanyModule1.CurrentCompany
    lateinit var currentCompany: Company

    @Inject
    @CompanyModule1.LastCompany
    lateinit var lastCompany: Company


    @ApplicationContext
    @Inject
    lateinit var appContext: Context

    @ActivityContext
    @Inject
    lateinit var actContext: Context


    //在Activity中的2个实例将是同一个对象
    @Inject
    lateinit var work: Work

    @Inject
    lateinit var work1: Work

    @Inject
    lateinit var codeV2: CodeV2


    @Inject
    lateinit var student: Student

    @Inject
    lateinit var student1: Student

    @Inject
    lateinit var tools: tools

    @Inject
    lateinit var tools1: tools

    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        Log.e(TAG, "tools：" + tools.hashCode())
        Log.e(TAG, "tools1：" + tools1.hashCode());

        Log.e(TAG, "student ：" + student.hashCode());
        Log.e(TAG, "student1 ：" + student1.hashCode());

        car.drive(" ZZZTTT ")


        currentCompany.getCompany()

        lastCompany.getCompany()



        work.getWork()

        codeV2.getWork()


        initView()


        var call: Call<MyWeather> = WheatherApi.getApi().getWheatherBeiJin("上海")
        call.enqueue(object : Callback<MyWeather> {
            override fun onResponse(call: Call<MyWeather>, response: Response<MyWeather>) {
                Log.d(TAG, "response:" + response.body())
            }

            override fun onFailure(call: Call<MyWeather>, t: Throwable) {
                Log.e(TAG, "t:$t")
            }
        })


        var wheatherGroup: Call<MyWeather> = WheatherApi.getApi().getWheatherGroup("cn", "10")
        wheatherGroup.enqueue(object : Callback<MyWeather> {
            override fun onResponse(call: Call<MyWeather>, response: Response<MyWeather>) {
                Log.d(TAG, "response:" + response.body())
            }

            override fun onFailure(call: Call<MyWeather>, t: Throwable) {
                Log.e(TAG, "t:$t")
            }
        })
    }

    private fun initView() {
        binding.button.setOnClickListener {
            TestActivityV2.start(this@MainActivity)
        }
    }
}